﻿using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using Framework.Game;
using Game.Input;
using UnityEngine;

public class RoleCtrl : MonoBehaviour
{

    private GameObject m_roleNode;
    private Animator m_roleAnimator;
    
    
    void Start()
    {
        m_roleNode = transform.GetChild(0).gameObject;
        m_roleAnimator = m_roleNode.GetComponent<Animator>();
        var input = GameManager.instance.input;
        input.AddListener<InputInfo>(InputBase.Event.MOVE_DIR_CHG, this.onMoveDirChg);
        input.enable = true;

        var camera = Camera.main;
        var cameraCtrl = camera.GetComponent<CameraCtrl>();
        cameraCtrl.FollowRole(this.gameObject, new Vector3(0.01575822f,3.412574f,-3.550182f));
    }

    private  void onMoveDirChg(InputInfo inputInfo)
    {
        
        //Debug.Log("输出" + inputInfo);
        if (inputInfo.isMoving)
        {
            var moveDir = inputInfo.moveDir * 0.05f;
            
            transform.position += new Vector3(moveDir.x, 0, moveDir.y);
            
            m_roleAnimator.SetBool("isRunning", true);
            var targetPos = transform.position + new Vector3(moveDir.x, 0, moveDir.y);
            transform.LookAt(targetPos);
        }
        else
        {
            m_roleAnimator.SetBool("isRunning", false);            
        }
        
        
    }
    

}
